import { fakeAnswerRelevanceData, fakeAnswerRelevanceDataForHot, fakeAnswerRelevanceDataForCapacity } from '@/services/datastatistics';
import { editQa } from '@/services/knowledgemanagement';

export default {
  namespace: 'relatedKnowledge',
  state: {
    data: {
      qaList: [],
      total: 0,
      suggestList: [],
    },
  },

  effects: {
    *get({ payload }, { call, put }) {
      const response = yield call(fakeAnswerRelevanceData, payload);
      yield put({
        type: 'save',
        payload: { data: { ...response } },
      });
    },
    *getRelatedList({ payload, callback }, { call, put }) {
      const response = yield call(fakeAnswerRelevanceData, payload);
      if (callback && typeof callback === 'function') {
        callback(response);
      }
      yield put({
        type: 'save',
        payload: response,
      });
    },
    *getRelatedListForHot({ payload, callback }, { call, put }) {
      const response = yield call(fakeAnswerRelevanceDataForHot, payload);
      if (callback && typeof callback === 'function') {
        callback(response);
      }
      yield put({
        type: 'save',
        payload: response,
      });
    },
    *getRelatedListForCapacity({ payload, callback }, { call, put }) {
      const response = yield call(fakeAnswerRelevanceDataForCapacity, payload);
      if (callback && typeof callback === 'function') {
        callback(response);
      }
      yield put({
        type: 'save',
        payload: response,
      });
    },
  },

  reducers: {
    save(state, { payload }) {
      return {
        ...state,
        ...payload,
      };
    },
  },
};
